package com.owc.controller.admin;

import com.owc.domain.BaseResult;
import com.owc.domain.PageBean;
import com.owc.domain.dto.admin.SystemConfigDTO;
import com.owc.domain.dto.admin.UpdateRecordDTO;
import com.owc.domain.vo.admin.ModifyVoAdmin;
import com.owc.domain.vo.admin.RateConfigVo;
import com.owc.domain.vo.admin.SystemConfigVo;
import com.owc.service.admin.SystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @Author Jackies
 * @Date 2019/12/18 23:22
 * @Description TODO://
 **/
@RestController
@RequestMapping(value = "/admin/system/")
@Api(tags = "(*)系统配置管理")
public class SystemController {

	@Autowired
	private SystemService systemService;

	@PostMapping(value = "getConfig")
	@ApiOperation("获取系统配置")
	public BaseResult<SystemConfigDTO> getConfig(){
		return BaseResult.success(systemService.getSystemConfig());
	}

	@PostMapping(value = "/updateConfig")
	@ApiOperation("更新系统配置")
	public BaseResult<Boolean> updateConfig(@RequestBody SystemConfigVo systemConfigVo){
		return BaseResult.success(systemService.updateConfig(systemConfigVo));
	}

	@PostMapping(value = "/updateRateConfig")
	@ApiOperation("(manage-V2)更新汇率配置")
	public BaseResult<Boolean> updateRateConfig(@RequestBody RateConfigVo rateConfigVo){
		return BaseResult.success(systemService.updateRateConfig(rateConfigVo));
	}

	@PostMapping(value = "/modifyPassword")
	@ApiModelProperty("修改密码")
	public BaseResult<Boolean> modifyPassword(@RequestBody @Valid ModifyVoAdmin modifyVoAdmin){
		return BaseResult.success(systemService.modifyPassword(modifyVoAdmin));
	}

	@GetMapping(value = "/getUpdateRateConfigLogs")
	@ApiOperation("(manage-V2)获取汇率修改记录")
	public BaseResult<UpdateRecordDTO> getUpdateRateConfigLogs(@RequestParam @Valid @NotNull(message = "选择分页参数") Integer pageIndex,
															   @NotNull(message = "选择分页参数") Integer pageSize){
		return BaseResult.makePageBean(systemService.getUpdateRateConfigLogs(pageIndex,pageSize));
	}

}
